/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifAdministrarStock.java
 *
 * Created on 01-sep-2010, 16:24:07
 */

package GestionMovimientos;

import administracion.delegate.GestionPedidosDelegate;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import suministros.ejb30.TO.EmpresaTO;
import administracion.helper.Listas;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.propiedades.Propiedades;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.NumberFormatter;
import suministros.ejb30.TO.AlmacenTO;
import suministros.ejb30.TO.StockAlmacenTO;
import suministros.ejb30.TO.SubAlmacenTO;
import suministros.ejb30.TO.SuministroStockTO;
import suministros.ejb30.TO.SuministroTO;
import suministros.ejb30.TO.ZonaTO;
import suministros.ejb30.entity.Empresa;
import suministros.ejb30.entity.StockAlmacen;
import suministros.ejb30.entity.StockAlmacenPK;

/**
 *
 * @author Diana
 */
public class jifAdministrarStock extends javax.swing.JInternalFrame {
   private ListDataIntelliHints intelliHintsSuministros;
    SuministroTO suministro;
    jifIngresosAlmacen jpPadre;
    DefaultFormatterFactory currFactory;
    String empresa;
    List<EmpresaTO> empresas;
    List<ZonaTO> zonas;
    private List<SuministroStockTO> stock_suministro;
    /** Creates new form jifAdministrarStock */
    public jifAdministrarStock() {
        initComponents();
        empresas = Listas.getEmpresas();
        if(empresas.isEmpty()){
            this.jCheckBox1.setEnabled(false);
        }
        this.jCheckBox1.setSelected(false);
        this.llenarComboEmpresa();
        this.llenarComboZonas();
        cargaHintsIndependientes();
        this.jcbEmpresa.setEnabled(false);
    }
    private void llenarComboEmpresa() {
        empresas = null;
        List listaPaises_cbo = this.cboBeanBindingEmpresa1.getLista();
        listaPaises_cbo.clear();
        try
        {
           if(this.jCheckBox1.isSelected()){
                empresas = Listas.getEmpresas();
            }
            else{
                empresas = Listas.getEmpresaPrincipal();
            }
          this.cboBeanBindingEmpresa1.setLista(empresas);
          this.bindingGroup.bind();
          this.jcbEmpresa.updateUI();
          this.jcbEmpresa.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener empresas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboZonas() {
        zonas = null;
        List listaPaises_cbo = this.cboBeanBindingZona1.getLista();
        listaPaises_cbo.clear();
        try
        {
          zonas = Listas.getZonas();
          this.cboBeanBindingZona1.setLista(zonas);
          this.bindingGroup.bind();
          this.jcbZona.updateUI();
          this.jcbZona.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener zonas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
       private void llenarComboAlmacenZona() {
           try {
                  if (this.jcbZona.getSelectedItem() != null) {
                    ZonaTO selected = (ZonaTO)this.jcbZona.getSelectedItem();
                    List listaAlmacen = null;
                    List listaAlmacen_cbo = this.cboBeanBindingAlmacen1.getLista();
                    listaAlmacen_cbo.clear();
                    listaAlmacen = Listas.getAlmacenEnZona(selected);
                    this.cboBeanBindingAlmacen1.setLista(listaAlmacen);
                    this.bindingGroup.bind();
                    this.jcbAlmacen.updateUI();
                    this.jcbAlmacen.setSelectedIndex(0);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, e);
            }
     }

     private void llenarComboUbicacionAlmacen() {
       try {
                  if (this.jcbAlmacen.getSelectedItem() != null) {
                    AlmacenTO selected = (AlmacenTO)this.jcbAlmacen.getSelectedItem();
                    List listaSubAlmacen = null;
                    List listaSubAlmacen_cbo = this.cboBeanBindingSubAlmacen1.getLista();
                    listaSubAlmacen_cbo.clear();
                    listaSubAlmacen = Listas.getSubAlmacenEnAlmacen(selected);
                    this.cboBeanBindingSubAlmacen1.setLista(listaSubAlmacen);
                    this.bindingGroup.bind();
                    this.jcbSubAlmacen.updateUI();
                    this.jcbSubAlmacen.setSelectedIndex(0);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Sub Almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, e);
            }
     }
    private void limpiar() {
        this.jtfCodSuministro.setText("");
        this.jtfDescSuministro.setText("");
        this.jftfCantidad.setValue(new Double(0.0D));
        this.jtfCodSuministro.requestFocus();

  }
     private void construirMascaras() {
    NumberFormat editFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);

    editFormat.setGroupingUsed(false);

    NumberFormatter enFormat = new NumberFormatter(editFormat);

    this.currFactory = new DefaultFormatterFactory(enFormat, enFormat, enFormat);

    enFormat.setAllowsInvalid(true);
  }
    private void cargaHintsIndependientes() {
    this.intelliHintsSuministros = new ListDataIntelliHints(this.jtfDescSuministro, Listas.getSuministros());
  }
   private void buscarSuministros()
  {
    this.suministro = null;
    SuministroTO sumi;
    if (this.jtfCodSuministro.getText().trim().length() < 1) {

      try { sumi = (SuministroTO)this.intelliHintsSuministros.getSelectedHint();
      } catch (NullPointerException ex) {
        sumi = null;
      }
    } else {
      sumi = Listas.getSuministroCodigo(this.jtfCodSuministro.getText().trim());
    }

    if (sumi == null) {
      Utiles_MensajesDialogo.mensajeError("El suministro no existe!");
      this.jtfDescSuministro.setText("");
      this.jbAceptar.setEnabled(false);
     } else {
          String  IdSubalmacen=((SubAlmacenTO)this.jcbSubAlmacen.getSelectedItem()).getCodSubAlmacen();
         String  emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
            try {
              StockAlmacenTO  stockto=  GestionPedidosDelegate.getInstance().getStockSuministroUbicacion(sumi.getId_suministro(), IdSubalmacen, emp);
              if(stockto == null){
                this.jftfCantidad.setText("0");
              }
              else{
                this.jftfCantidad.setText(stockto.getStockminimo()+"");
              }
            } catch (Exception ex) {
                Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
            }

      this.jtfDescSuministro.setText(sumi.toString());
      this.jtfCodSuministro.setText(sumi.getId_suministro());
      this.jbAceptar.setEnabled(true);
      this.jftfCantidad.requestFocus();
      this.suministro = sumi;
    }
  }
 public BigDecimal cargarSock(int subalmacen){
     BigDecimal stockactual= BigDecimal.ZERO;
      try {

          String em= empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
            this.stock_suministro = GestionPedidosDelegate.getInstance().getStockSuministro(this.jtfCodSuministro.getText(), em);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }
       if(!stock_suministro.isEmpty()){
          for(SuministroStockTO stockto: stock_suministro){
              if(stockto.getIdubicacion()==subalmacen){
                  stockactual=stockto.getStock();
              }
          }
      }
      else{
        stockactual= BigDecimal.ZERO;
      }
     return stockactual;

   }
 public void grabarDatos(){
      String  emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
            String  IdSubalmacen=((SubAlmacenTO)this.jcbSubAlmacen.getSelectedItem()).getCodSubAlmacen();
            try {
              StockAlmacenTO  stockto=  GestionPedidosDelegate.getInstance().getStockSuministroUbicacion(this.jtfCodSuministro.getText(), IdSubalmacen, emp);
              if(stockto==null){
                  StockAlmacenPK stockpk= new StockAlmacenPK(this.jtfCodSuministro.getText(), IdSubalmacen);
                  StockAlmacen stock= new StockAlmacen(stockpk);
                  stock.setIdEmpresa(new Empresa(emp));
                  stock.setStockMinimo(new BigDecimal(this.jftfCantidad.getText()).setScale(2));
                  stock.setStock(cargarSock(Integer.parseInt(IdSubalmacen)));
                  GestionPedidosDelegate.getInstance().registrarStockAlmacen(Propiedades.getUsuario(), Propiedades.getMac(), stock, 1);
              }
              else{
                
                  StockAlmacenPK stockpk= new StockAlmacenPK(stockto.getId_suministro(),stockto.getId_subalmacen());
                  StockAlmacen stock= new StockAlmacen(stockpk);
                  stock.setIdEmpresa(new Empresa(emp));
                  stock.setStockMinimo(new BigDecimal(this.jftfCantidad.getText()).setScale(5));
                  stock.setStock(stockto.getStock());
                  GestionPedidosDelegate.getInstance().registrarStockAlmacen(Propiedades.getUsuario(), Propiedades.getMac(), stock, 2);
                  
              }
              Utiles_MensajesDialogo.mensajeExito();

            } catch (Exception ex) {
                 Utiles_MensajesDialogo.mensajeError("No se puedo realizar la transaccion");
            }
 }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingEmpresa1 = new administracion.BeanBinding.CboBeanBindingEmpresa();
        cboBeanBindingZona1 = new administracion.BeanBinding.CboBeanBindingZona();
        cboBeanBindingSubAlmacen1 = new administracion.BeanBinding.CboBeanBindingSubAlmacen();
        cboBeanBindingAlmacen1 = new administracion.BeanBinding.cboBeanBindingAlmacen();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jtfCodSuministro = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jftfCantidad = new javax.swing.JFormattedTextField();
        this.jftfCantidad.setFormatterFactory(this.currFactory);
        jLabel16 = new javax.swing.JLabel();
        jcbEmpresa = new javax.swing.JComboBox();
        jcbZona = new javax.swing.JComboBox();
        jcbSubAlmacen = new javax.swing.JComboBox();
        jtfDescSuministro = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jcbAlmacen = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel15 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jbAceptar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();

        setIconifiable(true);
        setTitle("ADMINISTRAR STOCK MINIMO");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos del Suministro", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        jLabel9.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel9.setText("COD.SUMINISTRO");

        jtfCodSuministro.setFont(new java.awt.Font("Arial 12 Simple 12 Simple", 0, 12));
        jtfCodSuministro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCodSuministroActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel12.setText("STOCK MINIMO");

        jftfCantidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jftfCantidadActionPerformed(evt);
            }
        });
        jftfCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jftfCantidadKeyPressed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel16.setText("UBICACION:");

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingEmpresa1, eLProperty, jcbEmpresa);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbEmpresaActionPerformed(evt);
            }
        });
        jcbEmpresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbEmpresaKeyPressed(evt);
            }
        });

        jcbZona.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingZona1, eLProperty, jcbZona);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbZona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbZonaActionPerformed(evt);
            }
        });
        jcbZona.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbZonaKeyPressed(evt);
            }
        });

        jcbSubAlmacen.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingSubAlmacen1, eLProperty, jcbSubAlmacen);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbSubAlmacen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbSubAlmacenKeyPressed(evt);
            }
        });

        jtfDescSuministro.setFont(new java.awt.Font("Arial 12 Simple 12 Simple", 0, 12));
        jtfDescSuministro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDescSuministroActionPerformed(evt);
            }
        });
        jtfDescSuministro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfDescSuministroKeyPressed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel11.setText("SUCURSAL");

        jcbAlmacen.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingAlmacen1, eLProperty, jcbAlmacen);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbAlmacen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbAlmacenActionPerformed(evt);
            }
        });
        jcbAlmacen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbAlmacenKeyPressed(evt);
            }
        });

        jCheckBox1.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jCheckBox1.setText("OTRAS EMPRESAS");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel15.setText("ALMACEN:");

        jLabel10.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel10.setText("DESC.SUMINISTRO");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox1)
                    .addComponent(jLabel12)
                    .addComponent(jLabel11)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jtfCodSuministro, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                            .addComponent(jcbZona, 0, 104, Short.MAX_VALUE)
                            .addComponent(jftfCantidad))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jcbAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcbSubAlmacen, 0, 119, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addGap(10, 10, 10)
                                .addComponent(jtfDescSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel12, jLabel9});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox1))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbZona)
                            .addComponent(jLabel11))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(9, 9, 9)
                                .addComponent(jtfCodSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(jcbAlmacen)
                            .addComponent(jLabel16)
                            .addComponent(jcbSubAlmacen))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
                            .addComponent(jtfDescSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
                    .addComponent(jftfCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jbAceptar.setFont(new java.awt.Font("Arial", 0, 12));
        jbAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbAceptar.setMnemonic('A');
        jbAceptar.setText("ACEPTAR");
        jbAceptar.setToolTipText("Registrar el pedido");
        jbAceptar.setEnabled(false);
        jbAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAceptarActionPerformed(evt);
            }
        });
        jbAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbAceptarKeyPressed(evt);
            }
        });

        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbCancelar.setMnemonic('C');
        jbCancelar.setText("CERRAR");
        jbCancelar.setToolTipText("Cancelar la Operacion");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jbCancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbCancelarKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(219, 219, 219)
                .addComponent(jbAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbCancelar)
                .addContainerGap(264, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbAceptar)
                    .addComponent(jbCancelar)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtfDescSuministroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDescSuministroActionPerformed
       if(this.jcbSubAlmacen.getSelectedIndex()>=0){
            buscarSuministros();
       }
       else{
           Utiles_MensajesDialogo.mensajeAlerta("No ha seleccionado ninguna ubicacion");
       }
}//GEN-LAST:event_jtfDescSuministroActionPerformed

    private void jtfDescSuministroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescSuministroKeyPressed

        if (this.jtfCodSuministro.getText().trim().length() > 0)
            this.jtfCodSuministro.setText("");
}//GEN-LAST:event_jtfDescSuministroKeyPressed

    private void jtfCodSuministroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCodSuministroActionPerformed

        if (this.jtfCodSuministro.getText().trim().length() < 1)
            this.jtfDescSuministro.requestFocus();
        else
           if(this.jcbSubAlmacen.getSelectedIndex()>=0){
            buscarSuministros();
           }
           else{
               Utiles_MensajesDialogo.mensajeAlerta("No ha seleccionado ninguna ubicacion");
           }
}//GEN-LAST:event_jtfCodSuministroActionPerformed

    private void jftfCantidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jftfCantidadActionPerformed

}//GEN-LAST:event_jftfCantidadActionPerformed

    private void jftfCantidadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jftfCantidadKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbAceptar.requestFocus();
        }
}//GEN-LAST:event_jftfCantidadKeyPressed

    private void jbAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAceptarActionPerformed
        if(this.jcbSubAlmacen.getSelectedIndex()>=0){
           int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea registrar el stock minimo al suministro?",
          "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
         if(res==javax.swing.JOptionPane.YES_OPTION){
            this.grabarDatos();
         }
        }
        

        

}//GEN-LAST:event_jbAceptarActionPerformed

    private void jbAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbAceptarKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbAceptar.doClick();
        }
}//GEN-LAST:event_jbAceptarKeyPressed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        
        this.dispose();
}//GEN-LAST:event_jbCancelarActionPerformed

    private void jbCancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbCancelarKeyPressed
       
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbCancelar.doClick();
        }
}//GEN-LAST:event_jbCancelarKeyPressed

    private void jcbEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbEmpresaActionPerformed

    }//GEN-LAST:event_jcbEmpresaActionPerformed

    private void jcbEmpresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbEmpresaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            if(this.jcbEmpresa.getSelectedIndex()>=0){
                 this.jcbZona.requestFocus();
             }
        }
    }//GEN-LAST:event_jcbEmpresaKeyPressed

    private void jcbSubAlmacenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbSubAlmacenKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfCodSuministro.requestFocus();
        }
}//GEN-LAST:event_jcbSubAlmacenKeyPressed

    private void jcbAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbAlmacenActionPerformed
        if(this.jcbAlmacen.getSelectedIndex()>=0){
            this.llenarComboUbicacionAlmacen();
        }
}//GEN-LAST:event_jcbAlmacenActionPerformed

    private void jcbAlmacenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbAlmacenKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcbSubAlmacen.requestFocus();
        }
}//GEN-LAST:event_jcbAlmacenKeyPressed

    private void jcbZonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbZonaActionPerformed
        if(this.jcbZona.getSelectedIndex()>=0){
            llenarComboAlmacenZona();
        }
}//GEN-LAST:event_jcbZonaActionPerformed

    private void jcbZonaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbZonaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcbAlmacen.requestFocus();
        }
}//GEN-LAST:event_jcbZonaKeyPressed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if(this.jCheckBox1.isSelected()){
            this.jcbEmpresa.setEnabled(true);
        } else{
            this.jcbEmpresa.setEnabled(false);
        }
        this.llenarComboEmpresa();

}//GEN-LAST:event_jCheckBox1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.cboBeanBindingAlmacen cboBeanBindingAlmacen1;
    private administracion.BeanBinding.CboBeanBindingEmpresa cboBeanBindingEmpresa1;
    private administracion.BeanBinding.CboBeanBindingSubAlmacen cboBeanBindingSubAlmacen1;
    private administracion.BeanBinding.CboBeanBindingZona cboBeanBindingZona1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jbAceptar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JComboBox jcbAlmacen;
    private javax.swing.JComboBox jcbEmpresa;
    private javax.swing.JComboBox jcbSubAlmacen;
    private javax.swing.JComboBox jcbZona;
    private javax.swing.JFormattedTextField jftfCantidad;
    private javax.swing.JTextField jtfCodSuministro;
    private javax.swing.JTextField jtfDescSuministro;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
